package com.blb.exception;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@ControllerAdvice
public class MyException {

    @ExceptionHandler(value = UnauthorizedException.class)
    public String UnauthorizedException(UnauthorizedException e){
        return "403";
    }

    @ResponseBody
    @ExceptionHandler(value = UnknownAccountException.class)
    public String UnknownAccountException(UnknownAccountException e, RedirectAttributes model){
        return "{\"result\":\"userFalse\"}";
    }

    @ResponseBody
    @ExceptionHandler(value = IncorrectCredentialsException.class)
    public String IncorrectCredentialsException(IncorrectCredentialsException e, RedirectAttributes model){
        return "{\"result\":\"passwordFalse\"}";
    }

    @ResponseBody
    @ExceptionHandler(value = LockedAccountException.class)
    public String LockedAccountException(LockedAccountException e, RedirectAttributes model){
        return "{\"result\":\"Locked\"}";
    }

}
